package repository.jooq.generated;

import static org.jooq.impl.DSL.*;

import java.sql.*;

import org.jooq.*;
import org.jooq.impl.*;
import org.jooq.util.jaxb.Configuration;
import org.jooq.util.jaxb.Jdbc;
import org.jooq.util.maven.example.routines.Insertrecipe;

public class TryTwo
{
	public static void main(String[] args)
	{
		Connection conn = null;

		String userName = "postgres";
		String password = "postgres";
		String url = "jdbc:postgresql:cook-with-granny";

		try
		{
			Class.forName("org.postgresql.Driver").newInstance();
			conn = DriverManager.getConnection(url, userName, password);
			System.out.println("ala bala");

			DSLContext create = DSL.using(conn, SQLDialect.POSTGRES);
			String pname = "test recipe";
			String purl = "http://test.org";
			String pimageurl = "http://facebook.com";
			String pcontent = "alabalanicaturskapanica :D";
			int ptime = 2;
			int res = -1;
			
			Insertrecipe ir = new Insertrecipe();
			ir.setPcontent(pcontent);
			//ir.setPimageurl(purl);
			ir.setPimageurl(pimageurl);
			ir.setPname(pname);
			ir.setPurl(purl);
			ir.setPtime(ptime);

			// System.out.println("ala = " + ir.getReturnValue());
			SelectSelectStep<Record1<Integer>> rr = create.select(ir.asField());
			Result<Record1<Integer>> rrr = rr.fetch();
			//res = rr.execute();
			System.out.println("can I believe result = " + res);
			if (ir == null)
				System.out.println("da null e");
			//Row tq = rrr.fieldsRow();
			int i = 0;
			System.out.println(rrr.get(0).value1());
			for (Record1<Integer> pp : rrr)
			{
				System.out.println(" \ni = " + i + "  pp = " + pp.value1());
				i++;
			}

			//if (tq == null)
			//	System.out.println("ebi mu maikata");
			//System.out.println("can I believe result = " + tq);
			// System.out.println("_ala = " +
			// ((Record1<Integer>)(rrr.get(0)).original()).getValue("id"));
			System.out.println(rrr.format());
			Result<Record> result = create.select().from("recipes").fetch();

			/*for (Record r : result)
			{
				System.out.println("id " + r.getValue("adm_id"));
			}*/

		} catch (Exception e)
		{
			// For the sake of this tutorial, let's keep exception handling
			// simple
			e.printStackTrace();
		} finally
		{
			if (conn != null)
			{
				try
				{
					conn.close();
				} catch (SQLException ignore)
				{
				}
			}
		}
	}
}
